package com.xbongbong.pay.platform.wechatpay.enums;

import lombok.Getter;

/**
 * 微信v3接口
 * @author 魏荣杰
 * @date 2021/1/13 09:47
 * @since
 * @version
 */
@Getter
public enum WeChatV3UrlEnum {
    /**
     * 获取平台证书
     */
    CERTIFICATES("/v3/certificates"),
    /**
     * 统一下单API
     */
    H5_UNIFIED_ORDER("/v3/pay/transactions/h5"),
    /**
     * 微信支付订单号查询
     */
    H5_QUERY_ORDER_WECHAT("/v3/pay/transactions/id/%s"),
    /**
     * 商户订单号查询
     */
    HT_QUERY_ORDER_MCH("/v3/pay/transactions/out-trade-no/%s"),
    /**
     * 关单API
     */
    H5_CLOSE_ORDER("/v3/pay/transactions/out-trade-no/%s/close"),
    /**
     * 申请退款API
     */
    H5_APPLY_REFUND("/secapi/pay/refund"),
    /**
     * 查询退款API
     */
    H5_QUERY_REFUND("/pay/refundquery"),
    /**
     * 小程序 统一下单 api
     */
    MINA_UNIFIED_ORDER("/v3/pay/transactions/jsapi"),
    /**
     * 申请退款
     */
    APPLY_REFUND("/v3/refund/domestic/refunds"),
    /**
     * 查询单笔退款
     */
    QUERY_REFUND("/v3/refund/domestic/refunds/%s"),
    /**
     * JSAPI/小程序下单API(服务商模式)
     */
    PARTNER_TRANSACTIONS_JSAPI("/v3/pay/partner/transactions/jsapi"),
    /**
     * H5下单API(服务商模式)
     */
    PARTNER_TRANSACTIONS_H5("/v3/pay/partner/transactions/h5"),
    /**
     * Native下单API(服务商模式)
     */
    PARTNER_TRANSACTIONS_NATIVE("/v3/pay/partner/transactions/native"),
    /**
     * 微信支付订单号查询(服务商模式)
     */
    PARTNER_QUERY_ORDER_WECHAT("/v3/pay/partner/transactions/id/%s"),
    /**
     * 商户订单号查询(服务商模式)
     */
    PARTNER_QUERY_ORDER_MCH("/v3/pay/partner/transactions/out-trade-no/%s"),
    /**
     * 关单(服务商模式)
     */
    PARTNER_CLOSE_ORDER("/v3/pay/partner/transactions/out-trade-no/%s/close"),
    ;

    private final String pattern;

    WeChatV3UrlEnum(String pattern) {
        this.pattern = pattern;
    }

    public static String getUrl(WeChatServerEnum weChatServerEnum, WeChatV3UrlEnum weChatV3UrlEnum, Object... param) {
        return weChatServerEnum.getDomain() + getUrlPath(weChatV3UrlEnum, param);
    }

    public static String getUrlTest(WeChatServerEnum weChatServerEnum, WeChatV3UrlEnum weChatV3UrlEnum, Object... param) {
        return weChatServerEnum.getDomain() + "/sandboxnew" + String.format(weChatV3UrlEnum.getPattern(), param);
    }

    public static String getUrlPath(WeChatV3UrlEnum weChatV3UrlEnum, Object... param) {
        return String.format(weChatV3UrlEnum.getPattern(), param);
    }
}
